import { NgModule,ModuleWithProviders  } from '@angular/core';
import { RouterModule, Routes,CanActivate} from '@angular/router';

import {LoginComponent,LayoutTopSideComponent,ErrorComponent,UserInsertComponent,UserListComponent } from '../components/components';
import {LoginResolve,ModelPermissionResolve} from "./resolves/resolves";



/**子列表路由*/
const userRoutes:Routes=[{
  path:"user",
  children:[
    {
    path:"list/:pageSize/:pageNum",
    component:UserListComponent,
    canActivate:[LoginResolve ]
    },
    {
    path:"insert",
    component:UserInsertComponent,
    canActivate:[LoginResolve ]
    },
    {
    path:"update",
    component:UserInsertComponent,
    canActivate:[LoginResolve ]
    }
   ],
  canActivate:[LoginResolve ]
}];




/**根路由*/
const appRoutes: Routes = [
  {
    path: 'login', component: LoginComponent
  },
  {
    path: 'index',
    component: LayoutTopSideComponent,
    data: { title: 'Index' },
    canActivate:[LoginResolve ],//登录验证
    resolve:{//权限
      rootTree:ModelPermissionResolve
    },
    children:userRoutes
  },
  {
    path: '', 
    redirectTo: '/login', 
    pathMatch: 'full' 
  },
  {
    path: '**', 
    component: ErrorComponent 
  }
];











export const appRoutingModule: ModuleWithProviders = RouterModule.forRoot(appRoutes);